<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="common/head :: htmlhead">
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">待审核列表</div>
                <div class="layui-card-body">
                    <table id="info_table" lay-filter="info_table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="table_operate">
    <a class="layui-btn layui-btn-xs" lay-event="xiangqing">详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="tongguo">审核通过并分配角色</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="butongguo">审核不通过</a>
</script>
<!--审核通过弹框-->
<div class="site-text" style="margin: 5%; display: none" id="check_tg">
    <div class="layui-form" action="" lay-filter="check_tg_form">
        <input type="hidden" name="id" id="userid_r" class="layui-input" >
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block" id="mycheckbox">

            </div>
        </div>
        <div class="layui-form-item" hidden>
            <div class="layui-input-block">
                <button id="check_tg_submit" class="layui-btn" lay-submit lay-filter="check_tg_submit">
                    审核通过
                </button>
            </div>
        </div>
    </div>
</div>
<!--审核不通过弹框-->
<div class="site-text" style="margin: 5%; display: none" id="check_butg">
    <div class="layui-form" action="" lay-filter="check_butg_form">
        <input type="hidden" name="id" id="userid" class="layui-input" >
        <div class="layui-form-item">
            <label class="layui-form-label">审核意见</label>
            <div class="layui-input-block">
                <textarea name="shenheyijian" lay-verify="required" autocomplete="off" placeholder="请输入审核意见" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item" hidden>
            <div class="layui-input-block">
                <button id="check_butg_submit" class="layui-btn" lay-submit lay-filter="check_butg_submit">
                    审核不通过
                </button>
            </div>
        </div>
    </div>
</div>


<script>


    layui.use(['table','element','form'],function () {
        var table = layui.table
            ,element = layui.element
            ,form = layui.form;
        table.render({
            elem: '#info_table'
            ,url: '/getUserList_check'
            ,method : 'post'
            ,toolbar: true
            ,defaultToolbar: ['filter', 'print']
            ,cellMinWidth: 80
            ,page: true
            ,cols: [
                [
                    {field: 'username', title: '用户名'},
                    {field: 'createTime', title: '建立时间',
                        templet:function (row){
                            return createTime(row.creattime);}
                    },
                    {field: 'usertype', title: '所属工业类别',
                        templet:function (row) {
                            if (row.usertype == 1) {
                                return "博物馆会员";
                            }else if(row.usertype == 2){
                                return "个人会员";
                            }else{
                                return "其他单位会员";
                            }
                        }},

                    {fixed: 'right', title:'操作', toolbar: '#table_operate', width:'25%'}
                ]
            ]
        });

        table.on('tool(info_table)', function(obj){
            var data = obj.data;
            if(obj.event === 'xiangqing'){
                var url='/registerinfo/check?id='+data.id;
                self.location = url;
            } else if(obj.event === 'tongguo'){
                layer.open({
                    type: 1
                    ,skin: 'layui-layer-molv'
                    ,area: ['40%', '60%']
                    ,title: ['请选择要分配的角色','font-size:18px']
                    ,btn: ['通过并分配角色', '取消']
                    ,shadeClose: true
                    ,shade: 0 //遮罩透明度
                    ,maxmin: true //允许全屏最小化
                    ,content:$("#check_tg")  //弹窗路径
                    ,success:function(layero,index){
                        $.ajax({
                            url:"/getRoleList",
                            async: false,
                            type:"POST",
                            dataType: "text",
                            success: function(res){
                                var roleList = jQuery.parseJSON(res).roleList;
                                if(roleList&&roleList.length>0){
                                    for(var i = 0; i < roleList.length;i++){
                                        var roleid = roleList[i].id;
                                        var rolename = roleList[i].name;
                                        $("#mycheckbox").append("<input name='role' type='checkbox' lay-skin='primary' title='"+rolename+"' value='"+roleid+"' ><br>");

                                    }
                                }
                            }
                        });
                        $("#userid_r").attr("value",data.id);
                        form.render(null, 'check_tg_form');

                    }
                    ,yes : function(index, layero) { // 确认按钮回调函数
                        form.on('submit(check_tg_submit)', function(data) {
                            if ($("input:checkbox[name='role']:checked").length == 0) {
                                alert("请先选择要分配的角色");
                                return;
                            }

                            var role_list = new Array();
                            $("input:checkbox[name='role']:checked").each(function(i){
                                role_list[i] = $(this).val();
                            });
                            data.field.role = role_list.join(",");
                            console.log(data.field);
                            $.ajax({
                                url:"/registercheck/tongguo",
                                async: false,
                                type:"POST",
                                dataType: "text",
                                data:data.field,
                                success: function(data){
                                    if(data==="error"){
                                        layer.msg('审核失败！', {icon: 2});
                                        layer.close(index);
                                    }else if(data==="success"){
                                        layer.msg('审核成功！', {icon: 1});
                                        location.reload()
                                    }
                                }
                            });
                            return false;
                        });
                        $('#check_tg_submit').click();

                    }
                    ,btn2 : function(index, layero) { // 取消按钮回调函数
                        layer.close(index); // 关闭弹出层
                    }
                });

            } else if(obj.event === 'butongguo'){
                layer.open({
                    type: 1
                    ,skin: 'layui-layer-molv'
                    ,area: ['40%', '40%']
                    ,title: ['请填写审核意见','font-size:18px']
                    ,btn: ['审核不通过', '取消']
                    ,shadeClose: true
                    ,shade: 0 //遮罩透明度
                    ,maxmin: true //允许全屏最小化
                    ,content:$("#check_butg")  //弹窗路径
                    ,success:function(layero,index){
                        $("#userid").attr("value",data.id);
                        form.render(null, 'check_butg_form');
                    }
                    ,yes : function(index, layero) { // 确认按钮回调函数
                        form.on('submit(check_butg_submit)', function(data) {
                            $.ajax({
                                url:"/registercheck/butongguo",
                                async: false,
                                type:"POST",
                                dataType: "text",
                                data:data.field,
                                success: function(data){
                                    if(data==="error"){
                                        layer.msg('审核失败！', {icon: 2});
                                        layer.close(index);
                                    }else if(data==="success"){
                                        layer.msg('审核成功！', {icon: 1});
                                        location.reload()
                                    }
                                }
                            });
                            return false;
                        });
                        $('#check_butg_submit').click();

                    }
                    ,btn2 : function(index, layero) { // 取消按钮回调函数
                        layer.close(index); // 关闭弹出层
                    }
                });
            }
        });

    });
    function createTime(v){
        var date = new Date(v);
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        m = m<10?'0'+m:m;
        var d = date.getDate();
        d = d<10?("0"+d):d;
        var h = date.getHours();
        h = h<10?("0"+h):h;
        var M = date.getMinutes();
        M = M<10?("0"+M):M;
        var str = y+"-"+m+"-"+d+" "+h+":"+M;
        return str;
    }
</script>

</body>
</html>
